import { get,post } from '../../utils/request'
const state = {
	// 用来保存查询出来的栏目信息
	categorys: [],
	total: 0,
}
const actions = {
	// 查询所有栏目信息
	findAllCategory(context, list) {
		// 异步操作
		get('/productCategory/pageQuery', list).then((res) => {
			let response = res.data.list;
			let total = res.data.total;
			context.commit('SET_CATEGORY', response);
			context.commit('SET_TOTAL', total);
		})
	},
	// 保存栏目信息
	saveCategory(context,list) {
		let response =  post('/productCategory/saveOrUpdate',list)
		return response
	},
	deleteCategoryX(context,list){
		let response = get('/productCategory/deleteById',list)
		return response
	}
}
const mutations = {
	// 修改state中的值
	SET_CATEGORY(state, response) {
		state.categorys = response
	},
	SET_TOTAL(state, total) {
		state.total = total
	}
}
export default {
	namespaced: true,
	state,
	actions,
	mutations
}